import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'appRouter.dart';

// 路由扩展方法
extension GoRouterExt on BuildContext {
  // 导航到指定路由
  void push(String location, {Object? extra}) {
    GoRouter.of(this).push(location, extra: extra);
  }

  // 替换当前路由
  void replace(String location, {Object? extra}) {
    GoRouter.of(this).replace(location, extra: extra);
  }

  // 返回上一级
  void pop<T extends Object?>([T? result]) {
    GoRouter.of(this).pop(result);
  }

  // 导航到指定路由并移除当前路由栈
  void go(String location, {Object? extra}) {
    GoRouter.of(this).go(location, extra: extra);
  }
}

// 导航工具类
class RouteUtil {
  // 导航到指定路由
  static Future<T?> push<T extends Object?>(String location, {Object? extra}) {
    return appRouter.push<T>(location, extra: extra);
  }

  // 替换当前路由
  static Future<T?> replace<T extends Object?>(
    String location, {
    Object? extra,
  }) {
    return appRouter.replace<T>(location, extra: extra);
  }

  // 返回上一级
  static void pop<T extends Object?>([T? result]) {
    appRouter.pop(result);
  }

  // 导航到指定路由并移除当前路由栈
  static void go(String location, {Object? extra}) {
    appRouter.go(location, extra: extra);
  }
}
